# 构建阶段
FROM node:20-alpine AS build
WORKDIR /app

# 设置npm镜像源加速依赖安装（可选）
RUN npm config set registry https://registry.npmjs.org/

# 复制项目文件
COPY package*.json ./

# 安装依赖
RUN npm install

# 复制源代码
COPY . .

# 构建生产版本
RUN npm run build

# 部署阶段
FROM nginx:alpine
# 复制构建好的前端文件到nginx
COPY --from=build /app/dist /usr/share/nginx/html

# 复制自定义nginx配置（nginx.conf应该位于frontend目录下）
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

# 启动nginx
CMD ["nginx", "-g", "daemon off;"]